package control;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dao.db;
import dao.newDB;
import model.ProjectManager;
import java.sql.*;


/**
 * Servlet implementation class insertname
 */
@WebServlet("/insertname")
public class insertname extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public insertname() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	
	}


	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();

		try	{
			//db database= new db();
			newDB database = new newDB();
			ProjectManager projectManager= new ProjectManager();
			String name = null;
			database.dbOpen();
			Connection connection = database.getConnection();
			//int connection = database.dbConnect();
			name = projectManager.InsertMessage(connection, request, response);
			if (name!=null)	{
				out.println("<div>"+name+"</div>");	
			}else{
				out.println("false");
			}
		}
		catch (Exception ex){
			out.println("Error: " + ex.getMessage());
			out.println("");
		}finally{
			out.close();
		}
	}

}
